<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('巡检登记')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: bootstrap-fileinput-css"/>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-osiRecord-reg">
            <input name="osiPlanType" th:value="${osiPlanType}" type="hidden">
            <h4 class="form-header h4">巡检登记</h4>
            <div class="row">
            	<div class="col-sm-3">
                    <div class="form-group">
                        <label class="col-sm-5 control-label is-required">衡器：</label>
                        <div class="col-sm-7" th:with="dictCode=${'womp_weighing_apparatus,code,name,code='''+waInfoMap.wacode+''''}">
                            <select name="waCode" class="form-control m-b" th:with="type=${@commdict.getDictList(dictCode)}" required readonly="readonly">
                        		<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                    		</select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="col-sm-5 control-label is-required">类型：</label>
                        <div class="col-sm-7">
                    		<select name="osiType" class="form-control m-b" th:with="type=${@commdict.getDictList('sys_dict_data,dict_value,dict_label,dict_type=semicolonsys_osi_typesemicolon and dict_value=semicolon'+workOrderMap.osi_type+'semicolon')}" required readonly="readonly">
                        		<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${dict.dictValue==workOrderMap.osi_type}"></option>
                    		</select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="col-sm-5 control-label is-required">工单号：</label>
                        <div class="col-sm-7">
                            <div class="input-group">
                        		<input name="workOrderId" class="form-control" type="text" th:value="${workOrderMap.get('id')}" required readonly="readonly">
                    		</div>
                        </div>
                    </div>
                </div>
                <div class="col-sm-3">
                	<div class="form-group">
						<label class="col-sm-5 control-label is-required">工单类型：</label>
						<div class="col-sm-7">
							<select name="workorderType" class="form-control m-b" th:with="type=${@commdict.getDictList('sys_dict_data,dict_value,dict_label,dict_type=semicolonwork_order_typesemicolon and dict_value=semicolon'+workOrderMap.type+'semicolon')}" required  readonly="readonly">
			              		<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${dict.dictValue==workOrderMap.type}"></option>
			                </select>
						</div>
					</div>
				</div>
            </div>
            <div class="row">
            	<div class="col-sm-3">
                    <div class="form-group">
                        <label class="col-sm-5 control-label is-required">巡检人：</label>
                        <div class="col-sm-7">
							<select name="osiUser" class="form-control m-b" th:with="type=${@commdict.getDictList('sys_user,login_name,user_name,login_name!=semicolonadminsemicolon')}" required>
                        		<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:selected="${dict.dictValue==loginName}"></option>
                    		</select>
                        </div>
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="col-sm-5 control-label is-required">日期：</label>
                        <div class="col-sm-7">
                            <div class="input-group date">
                        		<input name="osiDate" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                        		<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                    		</div>
                        </div>
                    </div>
                </div>
            	<div class="col-sm-6">
                    <div class="form-group">
                        <label class="col-sm-3 control-label is-required">说明：</label>
                        <div class="col-sm-9">
                            <textarea name="handleContent" class="form-control" rows="5" required></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <h4 class="form-header h4">巡检记录明细信息</h4>
            <div class="row">
                <div class="col-sm-12">
                    <button type="button" class="btn btn-white btn-sm" onclick="addColumn()"><i class="fa fa-plus"> 增加</i></button>
                    <button type="button" class="btn btn-white btn-sm" onclick="sub.delColumn()"><i class="fa fa-minus"> 删除</i></button>
                    <div class="col-sm-12 select-table table-striped">
                        <table id="bootstrap-table"></table>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: bootstrap-fileinput-js"/>
    <script th:inline="javascript">
        var prefix = ctx + "realtime";
        var osiItemIdDatas = [[${@commdict.getDictList('womp_osi_item,id,name')}]];
        var osiResultDatas = [[${@dict.getType('sys_ois_item_state')}]];
        $("#form-osiRecord-reg").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/workOrderHandle", $('#form-osiRecord-reg').serialize());
            }
        }

        $("input[name='osiDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(".file-upload").each(function (i) {
            var val = $("input[name='" + this.id + "']").val()
            $(this).fileinput({
                'uploadUrl': ctx + 'common/upload',
                initialPreviewAsData: true,
                initialPreview: [val],
                maxFileCount: 1,
                autoReplace: true
            }).on('fileuploaded', function (event, data, previewId, index) {
                $("input[name='" + event.currentTarget.id + "']").val(data.response.url)
            }).on('fileremoved', function (event, id, index) {
                $("input[name='" + event.currentTarget.id + "']").val('')
            })
            $(this).fileinput('_initFileActions');
        });

        $(function() {
            var options = {
                data: [[${osiIteList}]],
                pagination: false,
                showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                sidePagination: "client",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'index',
                    align: 'center',
                    title: "序号",
                    formatter: function (value, row, index) {
                    	var columnIndex = $.common.sprintf("<input type='hidden' name='index' value='%s'>", $.table.serialNumber(index));
                    	return columnIndex + $.table.serialNumber(index);
                    }
                },
                {
                    field: 'osiItemId',
                    align: 'center',
                    title: '检查项',
                    formatter: function(value, row, index) {
                        var name = $.common.sprintf("wompOsiRecordItemList[%s].osiItemId", index);
                        return $.common.dictToSelect(osiItemIdDatas, row.id, name);
                    }
                },
                {
                    field: 'osiResult',
                    align: 'center',
                    title: '巡检结果',
                    formatter: function(value, row, index) {
                        var name = $.common.sprintf("wompOsiRecordItemList[%s].osiResult", index);
                        return $.common.dictToSelect(osiResultDatas, value, name);
                    }
                },
                {
                    field: 'remark',
                    align: 'center',
                    title: '说明',
                    formatter: function(value, row, index) {
                        var html = $.common.sprintf("<input class='form-control' type='text' required name='wompOsiRecordItemList[%s].remark' value='%s'>", index, value);
                        return html;
                    }
                }]
            };
            $.table.init(options);
        });

        function addColumn() {
            var count = $("#" + table.options.id).bootstrapTable('getData').length;
            sub.editColumn();
        	
            $("#" + table.options.id).bootstrapTable('insertRow', {
                index: count,
                row: {
                    index: $.table.serialNumber(count),
                    osiItemId: "",
                    osiResult: "",
                    remark: "",
        	    }
            });
        }
    </script>
</body>
</html>